<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form id='form1'>
        <input type="text" name="uname" autocomplete="off">
        <input type="password" name="pass" id="">
        <button type="submit">阿牛</button>
        <script>
            var form = document.querySelector('#form1')

            form.addEventListener('submit', function (e) {
                e.preventDefault();


                var fd = new FormData(form)
                var xhr = new XMLHttpRequest()
                xhr.open('POST', 'http://www.liulongbin.top:3006/api/formdata')
                // 调用send函数
                xhr.send(fd)
                // 监听onreadystatechange事件
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4 && xhr.status === 200) {
                        // 获取服务器响应的数据
                        // console.log(xhr.responseText)

                        console.log(JSON.parse(xhr.responseText));
                    } 
                }
            })
        </script>
    </form>
</body>

</html>